// api/cart.js
const { request } = require("../utils/request.js");

/**
 * 获取购物车列表
 */
const getCartList = () => {
  return request({
    url: "/client/shopping-cart/getCartList",
    method: "GET",
  });
};

/**
 * 更新购物车商品数量
 * @param {Object} params - 参数
 * @param {String} params.cartId - 购物车ID
 * @param {Number} params.quantity - 数量
 */
const updateCartQuantity = (params) => {
  return request({
    url: "/client/shopping-cart/updateQuantity",
    method: "POST",
    data: params,
  });
};

/**
 * 删除购物车商品
 * @param {Object} params - 参数
 * @param {String} params.cartId - 购物车ID
 */
const deleteCartItem = (params) => {
  return request({
    url: "/client/shopping-cart/decrease",
    method: "POST",
    data: params,
  });
};

/**
 * 选择/取消选择购物车商品
 * @param {Object} params - 参数
 * @param {String} params.cartId - 购物车ID
 * @param {Boolean} params.selected - 是否选中
 */
const toggleCartItemSelection = (params) => {
  return request({
    url: "/client/shopping-cart/toggleSelection",
    method: "POST",
    data: params,
  });
};

/**
 * 全选/取消全选购物车商品
 * @param {Object} params - 参数
 * @param {Boolean} params.selected - 是否全选
 */
const toggleAllCartItems = (params) => {
  return request({
    url: "/client/shopping-cart/toggleAll",
    method: "POST",
    data: params,
  });
};

/**
 * 增加购物车商品数量
 * @param {Object} params - 参数
 * @param {String} params.cartId - 购物车ID
 */
const increaseCartQuantity = (params) => {
  return request({
    url: "/client/shopping-cart/increase",
    method: "POST",
    data: params,
  });
};

/**
 * 减少购物车商品数量
 * @param {Object} params - 参数
 * @param {String} params.cartId - 购物车ID
 */
const decreaseCartQuantity = (params) => {
  return request({
    url: "/client/shopping-cart/decrease",
    method: "POST",
    data: params,
  });
};

/**
 * 选中购物车商品
 * @param {Object} params - 参数
 * @param {String} params.cartId - 购物车ID
 */
const chooseCartItem = (params) => {
  return request({
    url: "/client/shopping-cart/choose",
    method: "POST",
    data: params,
  });
};

/**
 * 取消选中购物车商品
 * @param {Object} params - 参数
 * @param {String} params.cartId - 购物车ID
 */
const cancelCartItem = (params) => {
  return request({
    url: "/client/shopping-cart/cancel",
    method: "POST",
    data: params,
  });
};

/**
 * 加入购物车
 * @param {Object} params - 参数
 * @param {String} params.spuId - 商品SPU ID
 * @param {String} params.skuId - 商品SKU ID
 * @param {Number} params.quantity - 数量
 */
const addToCart = (params) => {
  return request({
    url: "/client/shopping-cart/addToCart",
    method: "POST",
    data: params,
  });
};

module.exports = {
  getCartList,
  updateCartQuantity,
  deleteCartItem,
  toggleCartItemSelection,
  toggleAllCartItems,
  increaseCartQuantity,
  decreaseCartQuantity,
  chooseCartItem,
  cancelCartItem,
  addToCart,
};
